'use strict';

export default class extends think.Controller {
  /**
   * some base method in here
   */
   
	//初始化操作
	async __before(){

		//进行登陆判断
		let is_login = await this.is_login();
		if(!is_login){
			return this.redirect('/admin/public/signin');
		}		
		this.userinfo = await this.session('userinfo');
		if(!this.userinfo.headimg){
			this.userinfo.headimg = this.config('HEAD_IMG');
		}
		this.assign('userinfo',this.userinfo);
		
		//制作左边导航
		let aside = await this.model('menu').select();
		this.assign('aside',JSON.stringify(aside));
		
		
		
	}
   
	//判断是否登陆   	
	async is_login(){
		let userinfo = await this.session('userinfo');
		return think.isEmpty(userinfo)?false:userinfo.id;
	}
	
	//更新用户session
	async update_session(){
		let is_login = await this.is_login();
		if(is_login){
			let userinfo = await this.model('admin').where({id:is_login}).find();
			await this.session('userinfo',userinfo);
			return true;
		}else{
			return false;
		}	
	}
	
	
	//制作无限极分类导航
	
}